<?php 
class Tourismgoodscategoryspec extends CS_Controller
{
    //旅游商品管理
    public function _init()
    {
        $this->load->model('tourism_goods_category_attribute_model','tourism_goods_category_attribute');
        $this->load->model('tourism_goods_category_spec_model','tourism_goods_category_spec');
    }
    /*
     *规格属性修改
     * */
    public function edit($attr_id = 0)
    {

        $category_name = $this->tourism_goods_category_attribute->getCategoryNameByAttrId($attr_id);
        $spec_name = $this->tourism_goods_category_attribute->getAttrNameByAttrId($attr_id);
        $spec_value = $this->tourism_goods_category_spec->getSpecStringByAttId($attr_id);
        $resultObj = $this->tourism_goods_category_spec->getSpec($attr_id);
        if(!$attr_id || !$category_name || !$spec_name || !$spec_value){
            $this->error('tourismgoods/grid','','参数有误');
        }
        $data['id'] = $attr_id;
        $data['category_name'] = $category_name;
        $data['spec_name'] = $spec_name;
        $data['spec_value'] = $spec_value;
        $data['resultObj'] = $resultObj;


        $this->load->view('tourismgoodscategoryattribute/edit',$data);
    }
    public function editPost(){
        $param1['attr_id'] = (int)$this->input->post('category_id');
        $param1['attr_name'] = $this->input->post('attr_name',true);

        $value = $this->input->post('attribute_value',true);
        $value = str_replace('，',',',$value);
        $value = trim($value,',');
        $param2['attribute_value'] = explode(',',$value);

        $category_id = $this->tourism_goods_category_attribute->getCategoryIdByAttrId($param1['attr_id']);
        if(!$this->tourism_goods_category_spec->updateAttributeSpec($param1,$param2)){
            $this->success(base_url('tourismgoodscategoryattribute/grid/'.$category_id),'','修改成功');
        }else{
            $this->error(base_url('tourismgoodscategoryattribute/grid/'.$category_id),'','修改失败');
        }
    }
    public function delete($attr_id){
        $category_id = $this->input->get('category_id');
        $this->db->trans_start();
        $result = $this->tourism_goods_category_attribute->deleteAttributeByAttrId($attr_id);
        $this->db->trans_complete();
        if($result){
            $this->success(base_url('tourismgoodscategoryattribute/grid/'.$category_id),'','修改成功');
        }else{
            $this->error(base_url('tourismgoodscategoryattribute/grid/'.$category_id),'','修改失败');
        }
    }

    

}